<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>申报清单信息--可编辑</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <style>
        .table3 tr {
            height: 40px;
            line-height: 40px;
            border: 1px #ccc solid
        }
    </style>
</head>
<body>
<div class="content content_frame">
    <h3 class="mainTitle"><img src="${basePath}/images/icon3.png"/>申报清单信息</h3>
    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib">
            <a id="btnSave">
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存</a>
        </li>
        <c:if test="${declHead.status eq 'E1'}">
            <li class="dib">
                <a id="btnDeclare">
                    <i class='fa fa-check'></i>&nbsp;&nbsp;申&nbsp;报</a>
            </li>
        </c:if>
        <c:if test="${not empty declHead.seqNo && declHead.returnFlag == 0}">
            <li class="dib" onclick="changeDeclare('${declHead.id}')">
                <a>
                    <i class='icon-save'></i>&nbsp;&nbsp;退&nbsp;货</a>
            </li>
        </c:if>
        <li class="dib">
            <a onclick="javascript:history.go(-1)">
                <i class='fa fa-reply'></i>&nbsp;&nbsp;返&nbsp;回</a>
        </li>
    </ul>
    <br/>
    <form id="head_info">
        <input type="hidden" name="id" value="${declHead.id}">
        <table class="table3">
            <tr>
                <th colspan="4">清单表头信息</th>
            </tr>
            <tr>
                <td width="15%">清单编号</td>
                <td width="35%">
                    <label>
                        <input type="text" name="seqNo" value="${declHead.seqNo}"/>
                    </label>
                </td>
                <td width="15%">商户代码</td>
                <td width="35%">
                    <label><input type="text" name="ebCode" value="${declHead.ebCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>商户名称</td>
                <td>
                    <label><input type="text" name="ebName" value="${declHead.ebName}"/></label>
                </td>
                <td>电商平台代码</td>
                <td>
                    <label><input type="text" name="ebPlatId" value="${declHead.ebPlatId}"/></label>
                </td>
            </tr>
            <tr>
                <td>电商平台名称</td>
                <td>
                    <label><input type="text" name="ebPlatName" value="${declHead.ebPlatName}"/></label>
                </td>
                <td>物流企业代码</td>
                <td>
                    <label><input type="text" name="logiEnteCode" value="${declHead.logiEnteCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>物流企业名称</td>
                <td>
                    <label><input type="text" name="logiEnteName" value="${declHead.logiEnteName}"/></label>
                </td>
                <td>国内快递公司代码</td>
                <td>
                    <label><input type="text" name="expressCopCode" value="${declHead.expressCopCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>国内快递公司名称</td>
                <td>
                    <label><input type="text" name="expressCopName" value="${declHead.expressCopName}"/></label>
                </td>
                <td>代缴企业代码</td>
                <td>
                    <label><input type="text" name="paycopCode" value="${declHead.paycopCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>代缴企业名称</td>
                <td>
                    <label><input type="text" name="paycopName" value="${declHead.paycopName}"/></label>
                </td>
                <td>运单号</td>
                <td>
                    <label><input type="text" name="waybillId" value="${declHead.waybillId}"/></label>
                </td>
            </tr>
            <tr>
                <td>进出口类型</td>
                <td>
                    <label>
                        <ui:tsingletableautocomplete
                                keyFieldName="ieFlag"
                                valueFieldName="ieFlagXXXX"
                                tableName="DICT_ITEM"
                                key="ITEM_KEY"
                                value="ITEM_VALUE"
                                defaultKey="${declHead.ieFlag}"
                                groupId="ieType"
                        />
                    </label>
                </td>
                <td>贸易方式</td>
                <td>
                    <label><input type="text" name=""
                                  value="${func:dictItem('TRADE_MODE_QDC', declHead.tradeMode)}"/></label>
                </td>
            </tr>
            <tr>
                <td>退换货标志</td>
                <td>
                    <label><input type="text" name="" value="${declHead.returnFlagDisplay}"/></label>
                </td>
                <td>集装袋号</td>
                <td>
                    <label><input type="text" name="packId" value="${declHead.packId}"/></label>
                </td>
            </tr>
            <tr>
                <td>申报口岸</td>
                <td>
                    <label><input type="text" name="" value="${declHead.declPortDisplay}"/></label>
                </td>
                <c:if test="${declHead.ieFlag=='E'}">
                    <td>出境口岸</td>
                </c:if>
                <c:if test="${declHead.ieFlag=='I'}">
                    <td>进境口岸</td>
                </c:if>
                <td>
                    <label><input type="text" name="iePort" value="${declHead.iePort}"/></label>
                </td>
            </tr>
            <tr>
                <c:if test="${declHead.ieFlag=='E'}">
                    <td>出境日期</td>
                </c:if>
                <c:if test="${declHead.ieFlag=='I'}">
                    <td>进境日期</td>
                </c:if>
                <td>
                    <label>
                        <input type="text" name="ieDate" value="${declHead.ieDate}"/>
                    </label>
                </td>
                <td>经营单位代码</td>
                <td>
                    <label><input type="text" name="tradeCode" value="${declHead.tradeCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>经营单位名称</td>
                <td>
                    <label><input type="text" name="tradeName" value="${declHead.tradeName}"/></label>
                </td>
                <td>申报单位代码</td>
                <td>
                    <label><input type="text" name="agentCode" value="${declHead.agentCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>申报单位名称</td>
                <td>
                    <label><input type="text" name="agentName" value="${declHead.agentName}"/></label>
                </td>
                <td>监管场所代码</td>
                <td>
                    <label><input type="text" name="superPlaceCode" value="${declHead.superPlaceCode}"/></label>
                </td>
            </tr>
            <tr>
                <td>监管场所名称</td>
                <td>
                    <label><input type="text" name="superPlaceName" value="${declHead.superPlaceName}"/></label>
                </td>
                <td>运输方式</td>
                <td>
                    <label><input type="text" name="" value="${declHead.trafModeDisplay}"/></label>
                </td>
            </tr>
            <tr>
                <td>运输工具名称</td>
                <td>
                    <label><input type="text" name="trafName" value="${declHead.trafName}"/></label>
                </td>
                <td>航次</td>
                <td>
                    <label><input type="text" name="voyageNo" value="${declHead.voyageNo}"/></label>
                </td>
            </tr>
            <tr>
                <td>提运单号</td>
                <td>
                    <label><input type="text" name="billNo" value="${declHead.billNo}"/></label>
                </td>
                <c:if test="${declHead.ieFlag=='E'}">
                    <td>运抵国</td>
                </c:if>
                <c:if test="${declHead.ieFlag=='I'}">
                    <td>启运国</td>
                </c:if>
                <td>
                    <label><input type="text" name="" value="${declHead.tradeCountDisplay}"/></label>
                </td>
            </tr>
            <tr>
                <td>成交总价格</td>
                <td>
                    <label><input type="text" name="transTotalPrice" value="${declHead.transTotalPrice}"/></label>
                </td>
                <td>币制</td>
                <td>
                    <label><input type="text" name="" value="${orderHead.currDisplay}"/></label>
                </td>
            </tr>
            <tr>
                <td>成交总价格</td>
                <td>
                    <label><input type="text" name="transTotalPrice" value="${declHead.transTotalPrice}"/></label>
                </td>
                <td>重量</td>
                <td>
                    <label><input type="text" name="grossWeight" value="${declHead.grossWeight}"/></label>
                </td>
            </tr>
            <tr>
                <td>总件数</td>
                <td>
                    <label><input type="text" name="packNum" value="${declHead.packNum}"/></label>
                </td>
                <td>账册编号</td>
                <td>
                    <label><input type="text" name="manualNo" value="${declHead.manualNo}"/></label>
                </td>
            </tr>
            <tr>
                <td>发货人证件类型</td>
                <td>
                    <label><input type="text" name=""
                                  value="${func:dictItem('idType', declHead.ownerCertType)}"/></label>
                </td>
                <td>发货人证件号</td>
                <td>
                    <label><input type="text" name="ownerCertId" value="${declHead.ownerCertId}"/></label>
                </td>
            </tr>
            <tr>
                <td>发货人姓名</td>
                <td>
                    <label><input type="text" name="ownerName" value="${declHead.ownerName}"/></label>
                </td>
                <td>发货人地址</td>
                <td>
                    <label><input type="text" name="ownerAddr" value="${declHead.ownerAddr}"/></label>
                </td>
            </tr>
            <tr>
                <td>发货人电话</td>
                <td>
                    <label><input type="text" name="ownerTel" value="${declHead.ownerTel}"/></label>
                </td>
                <td>关联清单编号</td>
                <td>
                    <label><input type="text" name="relSeqNo" value="${declHead.relSeqNo}"/></label>
                </td>
            </tr>
            <tr>
                <td>关联运单号</td>
                <td>
                    <label><input type="text" name="relWaybillId" value="${declHead.relWaybillId}"/></label>
                </td>
                <td>关联物流企业代码</td>
                <td>
                    <label><input type="text" name="relLogiEntecode" value="${declHead.relLogiEntecode}"/></label>
                </td>
            </tr>
            <tr>
                <td>回执状态</td>
                <td colspan="3">
                    <label><input type="text" name="" value="${declHead.statusDisplay}" style="width: 100%"/></label>
                </td>
            </tr>
            <tr>
                <td>备注</td>
                <td colspan="3"><label><input type="text" name="note" value="${declHead.note}" style="width: 100%"/></label></td>
            </tr>
        </table>
    </form>
    <br/>
    <form id="body_info">
        <table id="goods_info" class="table3"></table>
    </form>
    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib">
            <a id="btnSave1">
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存</a>
        </li>
        <li class="dib">
            <a id="btnModify">
                <i class='fa fa-edit'></i>&nbsp;&nbsp;修&nbsp;改</a>
        </li>
    </ul>
    <br/>
    <table id="corptable">
    </table>
    <div id="corptablePage">
    </div>
    <br/>
    <form id="container_form">
        <table id="container_info" class="table3"></table>
    </form>
    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib">
            <a id="btnSave2">
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存</a>
        </li>
        <li class="dib">
            <a id="btnModify2">
                <i class='fa fa-edit'></i>&nbsp;&nbsp;修&nbsp;改</a>
        </li>
    </ul>
    <br/>
    <table id="container">
    </table>
    <div id="containerPage">
    </div>
    <br/>
</div>
<script type="text/javascript">
    $(function () {
        //加载表体列表
        showCbecElistItem('null');

        //加载集装箱信息列表
        showContainer('null');

        <!--设置列表页，偶数页td背景颜色-->
        $(".table3 td:even").css("background-color", "#f5f5f5");

        $("#corptable").jqGrid({
            datatype: "json",
            url: "${basePath}/declareDetailQdc/queryTGoodsListQdcList?relatedId=${id}",
            colNames: [
                'ID', '序号', '商品编码', '商品名称', '数量', '成交单位', '单价', '总价', '税款', '币制', '备注'
            ],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'gNo', index: 'gNo', width: 40},
                {name: 'codeTs', index: 'codeTs'},
                {name: 'gName', index: 'gName'},
                {name: 'gNum', index: 'gNum'},
                {name: 'gUnitDisplay', index: 'gUnitDisplay'},
                {name: 'price', index: 'price'},
                {name: 'totalPrice', index: 'totalPrice'},
                {name: 'taxPayment', index: 'taxPayment'},
                {name: 'currCodeDisplay', index: 'currCodeDisplay'},
                {name: 'note', index: 'note'}
            ],
            viewrecords: true,
            autowidth: true,
            height: 'auto',
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            rownumbers: false,
            rownumWidth: 15,
            multiselect: true,
            pager: "#corptablePage", //分页工具栏
            sortname: "",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            },
            ondblClickRow: function (rowid) {
                showCbecElistItem($("#corptable").jqGrid('getRowData', rowid).id);
            }
        });

        $("#container").jqGrid({
            datatype: "json",
            url: "${basePath}/declareDetailQdc/queryHeadContainerList?releatedId=${id}",
            colNames: ['ID', '集装箱编号', '集装箱型号', '备注'],
            colModel: [{name: 'id', index: 'id', hidden: true},
                {name: 'containerId', index: 'containerId'}, {
                    name: 'containerMd', index: 'containerMd'
                }, {name: 'note', index: 'note'}],
            viewrecords: true,
            autowidth: true,
            height: 'auto',
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            rownumbers: false,
            rownumWidth: 15,
            multiselect: true,
            pager: "#containerPage", //分页工具栏
            sortname: "",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                } else {
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            },
            ondblClickRow: function (rowid) {
                showContainer($("#container").jqGrid('getRowData', rowid).id);
            }
        });

        //保存表头信息
        $("#btnSave").bind("click", function () {
            if (!isValid('head_info')) {
                return;
            }
            $.ajax({
                url: "${basePath}/declareDetailQdc/updateTDeclformHeadQdc",
                dataType: "json",
                type: 'POST',
                data: $("#head_info").serialize(),
                success: function (data) {
                    if (data == 1) {
                        ShowMessages("保存成功", "系统提示", "msgok", null, 0);
                    } else {
                        ShowMessages("保存失败", "系统提示", "msgwaring", null, 0);
                    }
                }
            })
        });

        //保存表体信息
        $("#btnSave1").bind("click", function () {
            if ($("#body_info input[name='id']").val() == "") {
                ShowMessages("请先选择一条记录点击修改", "系统提示", "msgwaring", null, 0);
                return;
            }
            $.ajax({
                url: "${basePath}/declareDetailQdc/updateTGoodsListQdc",
                dataType: "json",
                type: 'POST',
                data: $("#body_info").serialize(),
                success: function (data) {
                    if (data == 1) {
                        ShowMessages("保存成功", "系统提示", "msgok", function () {
                            showCbecElistItem("null");
                            reloadGrid();
                        }, 0);
                    } else {
                        ShowMessages("保存失败", "系统提示", "msgwaring", null, 0);
                    }
                }
            })
        });

        //保存表体信息
        $("#btnSave2").bind("click", function () {
            if (!isValid('container_form')) {
                return;
            }
            if ($("#container_info input[name='id']").val() == "") {
                ShowMessages("请先选择一条记录点击修改", "系统提示", "msgwaring", null, 0);
                return;
            }
            $.ajax({
                url: "${basePath}/declareDetailQdc/updateContainerQdc",
                dataType: "json",
                type: 'POST',
                data: $("#container_form").serialize(),
                success: function (data) {
                    if (data == 1) {
                        ShowMessages("保存成功", "系统提示", "msgok", function () {
                            showContainer('null');
                            reloadGridContainer();
                        }, 0);
                    } else {
                        ShowMessages("保存失败", "系统提示", "msgwaring", null, 0);
                    }
                }
            })
        });

        //修改商品
        $("#btnModify").bind("click", function () {
            var jsonArr = getId("corptable");
            if (1 != jsonArr.length) {
                ShowMessages("请选择一条记录进行修改", "系统提示", "msgwaring", null, 0);
                return;
            }
            showCbecElistItem(jsonArr[0].id);
        });

        //修改集装箱
        $("#btnModify2").bind("click", function () {
            var jsonArr = getId("container");
            if (1 != jsonArr.length) {
                ShowMessages("请选择一条记录进行修改", "系统提示", "msgwaring", null, 0);
                return;
            }
            showContainer(jsonArr[0].id);
        });

        //申报
        $("#btnDeclare").bind("click", function () {
            $.post("${basePath}/importB2CDirect/personalDeclQdc/declare", {id: $("input[name='id']").val()}, function (data) {
                if (data) {
                    ShowMessages("已上报，请等待回执", "系统提示", "msgok", function () {
                        window.location.reload();
                    }, 0);
                } else {
                    ShowMessages(data, "系统提示", "msgwaring", function () {
                        window.location.reload();
                    }, 0);
                }
            });
        });

        formValidate('head_info', {
            relSeqNo: {
                maxNum: [19]
            },
            relWaybillId: {
                maxBytes: 32
            },
            waybillId: {
                maxBytes: 32
            },
            relLogiEntecode: {
                maxBytes: 32
            },
            packId: {
                maxBytes: 32
            },
            manualNo: {
                maxBytes: 12
            },
            ownerCertId: {
                maxBytes: 18
            },
            ownerName: {
                maxBytes: 64
            },
            tradeCode: {
                maxBytes: 10
            },
            tradeName: {
                maxBytes: 64
            },
            agentCode: {
                maxBytes: 10
            },
            agentName: {
                maxBytes: 64
            },
            trafName: {
                maxBytes: 32
            },
            voyageNo: {
                maxBytes: 32
            },
            billNo: {
                maxBytes: 32
            },
            transTotalPrice: {
                maxNum: [16, 2]
            },
            grossWeight: {
                maxNum: [16, 2]
            },
            ebCode: {
                maxBytes: 10
            },
            ebName: {
                maxBytes: 64
            },
            ebPlatName: {
                maxBytes: 64
            },
            logiEnteCode: {
                maxBytes: 9
            },
            logiEnteName: {
                maxBytes: 64
            },
            paycopCode: {
                maxBytes: 10
            },
            paycopName: {
                maxBytes: 64
            },
            superPlaceCode: {
                maxBytes: 4
            },
            superPlaceName: {
                maxBytes: 64
            },
            expressCopCode: {
                maxBytes: 9
            },
            expressCopName: {
                maxBytes: 64
            },
            note: {
                maxBytes: 512
            },
            packNum: {
                maxNum: [5]
            },
            ebPlatId: {
                maxBytes: 10
            },
            ownerTel: {
                maxNum: [16]
            },
            ownerAddr: {
                maxBytes: 512
            }
        });

        formValidate('container_form', {
            containerMd: {
                maxNum: [5]
            }
        })
    });

    //动态加载表体列表
    function showCbecElistItem(id) {
        $("#goods_info").load('${basePath}/declareDetailQdc/loadDeclareBodyEdit', {id: id}, function () {
        });
    }

    //退货
    function changeDeclare(id) {
        showConfirm("是否退货？", "", function () {
            $.post("${basePath}/changeDeclare/changeDeclareById", {id: id}, function (data) {
                if (data) {
                    ShowMessages("操作成功", "系统提示", "msgok", function () {
                        window.location.reload();
                    }, 0);
                } else {
                    ShowMessages("操作失败", "系统提示", "msgwaring", function () {
                        window.location.reload();
                    }, 0);
                }
            });
        });
    }

    function reloadGrid() {
        $("#corptable").jqGrid('setGridParam', {
            url: "${basePath}/declareDetailQdc/queryTGoodsListQdcList?relatedId=${id}",
            page: 1
        }).trigger("reloadGrid"); //重新载入
    }

    function reloadGridContainer() {
        $("#container").jqGrid('setGridParam', {
            url: "${basePath}/declareDetailQdc/queryHeadContainerList?releatedId=${id}",
            page: 1
        }).trigger("reloadGrid"); //重新载入
    }

    function showContainer(id) {
        $("#container_info").load('${basePath}/declareDetailQdc/loadDeclareContainerEdit', {id: id}, function () {
        });
    }

    function getModelVal(val) {
        $("#gModel").val(val)
    }
</script>
</body>
</html>

